const mongoose = require('mongoose');

const roleSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    unique: true,
    trim: true,
  },
  code: {
    type: String,
    required: true,
    unique: true,
    trim: true,
  },
  description: {
    type: String,
    trim: true,
  },
  permissions: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Permission',
  }],
  status: {
    type: Number,
    default: 1, // 1: 正常, 0: 禁用
  },
  sort: {
    type: Number,
    default: 0,
  },
}, {
  timestamps: true,
});

const Role = mongoose.model('Role', roleSchema);

module.exports = Role; 